package test1;

public class studentTest {
    public static void main(String[] args) {
        student[]arr=new student[3];

        student s1=new student(1,"小明",21);
        student s2=new student(2,"小王",19);
        student s3=new student(3,"小赵",25);

        arr[0]=s1;
        arr[1]=s2;
        arr[2]=s3;

        student s4=new student(4,"小李",22);

        boolean flag=contains(arr,s4.getId());
        if (flag){
            System.out.println("当前id重复，请修改id后再进行添加");
        }else {


        }
    }



    public static boolean contains(student[]arr,int id) {
        for (int i = 0; i < arr.length; i++) {
            student s =arr[i];
            int sid = s.getId();
            if (sid==id){
                return true;
            }
        }
        return false;
    }
}

/*1.创建长度为3的数组
  2.创建学生对象
  3.将对象填入数组
  4.再次创建一个学生对象
  5.唯一性判断
  6.添加学生对象
 */